1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.geronimo.ews.ws4j2ee.toWs;
18
19 import org.apache.axis.encoding.DefaultSOAPEncodingTypeMappingImpl;
20 import org.apache.axis.encoding.DefaultTypeMappingImpl;
21 import org.apache.axis.i18n.Messages;
22 import org.apache.axis.utils.CLArgsParser;
23 import org.apache.axis.utils.CLOption;
24 import org.apache.axis.utils.CLOptionDescriptor;
25 import org.apache.axis.utils.CLUtil;
26 import org.apache.axis.utils.ClassUtils;
27 import org.apache.axis.wsdl.fromJava.Emitter;
28 import org.apache.geronimo.ews.ws4j2ee.module.Module;
29 import org.apache.geronimo.ews.ws4j2ee.module.ModuleFactory;
30 import org.apache.axis.encoding.TypeMappingRegistryImpl;
31
32 import java.io.File;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36
37 /***
38 * @author hemapani
39 */
40 public class Ws4J2eeServerCLOptionParser implements Ws4J2eeDeployContext {
41 private Module module;
42 private String outPutLocation;
43 private String moduleLocation = null;
44 private String implStyle = GenerationConstants.USE_LOCAL_AND_REMOTE;
45 private String container = GenerationConstants.JBOSS_CONTAINER;
46
47 private String[] args;
48 private int indexToChange = -1;
49
50 /***
51 * @return
52 */
53 public String getOutPutLocation() {
54 return outPutLocation;
55 }
56
57 /***
58 * @param string
59 */
60 public void setOutPutLocation(String string) {
61 outPutLocation = string;
62 }
63
64
65
66 /***
67 * Field INHERITED_CLASS_OPT
68 */
69 protected static final int INHERITED_CLASS_OPT = 'a';
70
71 /***
72 * Field SOAPACTION_OPT
73 */
74 protected static final int SOAPACTION_OPT = 'A';
75
76 /***
77 * Field BINDING_NAME_OPT
78 */
79 protected static final int BINDING_NAME_OPT = 'b';
80
81 /***
82 * Field STOP_CLASSES_OPT
83 */
84 protected static final int STOP_CLASSES_OPT = 'c';
85
86 /***
87 * Field IMPORT_SCHEMA_OPT
88 */
89 protected static final int IMPORT_SCHEMA_OPT = 'C';
90
91 /***
92 * Field EXTRA_CLASSES_OPT
93 */
94 protected static final int EXTRA_CLASSES_OPT = 'e';
95
96 /***
97 * Field HELP_OPT
98 */
99 protected static final int HELP_OPT = 'h';
100
101 /***
102 * Field IMPL_CLASS_OPT
103 */
104 protected static final int IMPL_CLASS_OPT = 'i';
105
106 /***
107 * Field INPUT_OPT
108 */
109 protected static final int INPUT_OPT = 'I';
110
111 /***
112 * Field LOCATION_OPT
113 */
114 protected static final int LOCATION_OPT = 'l';
115
116 /***
117 * Field LOCATION_IMPORT_OPT
118 */
119 protected static final int LOCATION_IMPORT_OPT = 'L';
120
121 /***
122 * Field METHODS_ALLOWED_OPT
123 */
124 protected static final int METHODS_ALLOWED_OPT = 'm';
125
126 /***
127 * Field NAMESPACE_OPT
128 */
129 protected static final int NAMESPACE_OPT = 'n';
130
131 /***
132 * Field NAMESPACE_IMPL_OPT
133 */
134 protected static final int NAMESPACE_IMPL_OPT = 'N';
135
136 /***
137 * Field OUTPUT_OPT
138 */
139 protected static final int OUTPUT_OPT = 'o';
140
141 /***
142 * Field OUTPUT_IMPL_OPT
143 */
144 protected static final int OUTPUT_IMPL_OPT = 'O';
145
146 /***
147 * Field PACKAGE_OPT
148 */
149 protected static final int PACKAGE_OPT = 'p';
150
151 /***
152 * Field PORTTYPE_NAME_OPT
153 */
154 protected static final int PORTTYPE_NAME_OPT = 'P';
155
156 /***
157 * Field SERVICE_PORT_NAME_OPT
158 */
159 protected static final int SERVICE_PORT_NAME_OPT = 's';
160
161 /***
162 * Field SERVICE_ELEMENT_NAME_OPT
163 */
164 protected static final int SERVICE_ELEMENT_NAME_OPT = 'S';
165
166 /***
167 * Field TYPEMAPPING_OPT
168 */
169 protected static final int TYPEMAPPING_OPT = 'T';
170
171 /***
172 * Field USE_OPT
173 */
174 protected static final int USE_OPT = 'u';
175
176 /***
177 * Field OUTPUT_WSDL_MODE_OPT
178 */
179 protected static final int OUTPUT_WSDL_MODE_OPT = 'w';
180
181 /***
182 * Field METHODS_NOTALLOWED_OPT
183 */
184 protected static final int METHODS_NOTALLOWED_OPT = 'x';
185
186 protected static final int CLASSPATH_OPT = 'X';
187
188 /***
189 * Field STYLE_OPT
190 */
191 protected static final int STYLE_OPT = 'y';
192
193 protected static final int IMPL_STYLE_OPT = 'E';
194 protected static final int CONTAINER_OPT = 'J';
195
196 /***
197 * Define the understood options. Each CLOptionDescriptor contains:
198 * - The "long" version of the option. Eg, "help" means that "--help" will
199 * be recognised.
200 * - The option flags, governing the option's argument(s).
201 * - The "short" version of the option. Eg, 'h' means that "-h" will be
202 * recognised.
203 * - A description of the option for the usage message
204 */
205 protected CLOptionDescriptor[] options = new CLOptionDescriptor[]{
206 new CLOptionDescriptor("help", CLOptionDescriptor.ARGUMENT_DISALLOWED,
207 HELP_OPT, Messages.getMessage("j2wopthelp00")),
208 new CLOptionDescriptor("input", CLOptionDescriptor.ARGUMENT_REQUIRED,
209 INPUT_OPT, Messages.getMessage("j2woptinput00")),
210 new CLOptionDescriptor("output", CLOptionDescriptor.ARGUMENT_REQUIRED,
211 OUTPUT_OPT,
212 Messages.getMessage("j2woptoutput00")),
213 new CLOptionDescriptor("location",
214 CLOptionDescriptor.ARGUMENT_REQUIRED,
215 LOCATION_OPT,
216 Messages.getMessage("j2woptlocation00")),
217 new CLOptionDescriptor("portTypeName",
218 CLOptionDescriptor.ARGUMENT_REQUIRED,
219 PORTTYPE_NAME_OPT,
220 Messages.getMessage("j2woptportTypeName00")),
221 new CLOptionDescriptor("bindingName",
222 CLOptionDescriptor.ARGUMENT_REQUIRED,
223 BINDING_NAME_OPT,
224 Messages.getMessage("j2woptbindingName00")),
225 new CLOptionDescriptor("serviceElementName", CLOptionDescriptor.ARGUMENT_REQUIRED,
226 SERVICE_ELEMENT_NAME_OPT,
227 Messages.getMessage("j2woptserviceElementName00")),
228 new CLOptionDescriptor("servicePortName",
229 CLOptionDescriptor.ARGUMENT_REQUIRED,
230 SERVICE_PORT_NAME_OPT,
231 Messages.getMessage("j2woptservicePortName00")),
232 new CLOptionDescriptor("namespace",
233 CLOptionDescriptor.ARGUMENT_REQUIRED,
234 NAMESPACE_OPT,
235 Messages.getMessage("j2woptnamespace00")),
236 new CLOptionDescriptor("PkgtoNS",
237 CLOptionDescriptor.DUPLICATES_ALLOWED
238 + CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
239 PACKAGE_OPT,
240 Messages.getMessage("j2woptPkgtoNS00")),
241 new CLOptionDescriptor("methods",
242 CLOptionDescriptor.DUPLICATES_ALLOWED
243 + CLOptionDescriptor.ARGUMENT_REQUIRED,
244 METHODS_ALLOWED_OPT,
245 Messages.getMessage("j2woptmethods00")),
246 new CLOptionDescriptor("all", CLOptionDescriptor.ARGUMENT_DISALLOWED,
247 INHERITED_CLASS_OPT,
248 Messages.getMessage("j2woptall00")),
249 new CLOptionDescriptor("outputWsdlMode",
250 CLOptionDescriptor.ARGUMENT_REQUIRED,
251 OUTPUT_WSDL_MODE_OPT,
252 Messages.getMessage("j2woptoutputWsdlMode00")),
253 new CLOptionDescriptor("locationImport",
254 CLOptionDescriptor.ARGUMENT_REQUIRED,
255 LOCATION_IMPORT_OPT,
256 Messages.getMessage("j2woptlocationImport00")),
257 new CLOptionDescriptor("namespaceImpl",
258 CLOptionDescriptor.ARGUMENT_REQUIRED,
259 NAMESPACE_IMPL_OPT,
260 Messages.getMessage("j2woptnamespaceImpl00")),
261 new CLOptionDescriptor("outputImpl",
262 CLOptionDescriptor.ARGUMENT_REQUIRED,
263 OUTPUT_IMPL_OPT,
264 Messages.getMessage("j2woptoutputImpl00")),
265 new CLOptionDescriptor("implClass",
266 CLOptionDescriptor.ARGUMENT_REQUIRED,
267 IMPL_CLASS_OPT,
268 Messages.getMessage("j2woptimplClass00")),
269 new CLOptionDescriptor("exclude",
270 CLOptionDescriptor.DUPLICATES_ALLOWED
271 + CLOptionDescriptor.ARGUMENT_REQUIRED,
272 METHODS_NOTALLOWED_OPT,
273 Messages.getMessage("j2woptexclude00")),
274 new CLOptionDescriptor("stopClasses",
275 CLOptionDescriptor.DUPLICATES_ALLOWED
276 + CLOptionDescriptor.ARGUMENT_REQUIRED,
277 STOP_CLASSES_OPT,
278 Messages.getMessage("j2woptstopClass00")),
279 new CLOptionDescriptor("typeMappingVersion",
280 CLOptionDescriptor.ARGUMENT_REQUIRED,
281 TYPEMAPPING_OPT,
282 Messages.getMessage("j2wopttypeMapping00")),
283 new CLOptionDescriptor("soapAction",
284 CLOptionDescriptor.ARGUMENT_REQUIRED,
285 SOAPACTION_OPT,
286 Messages.getMessage("j2woptsoapAction00")),
287 new CLOptionDescriptor("style", CLOptionDescriptor.ARGUMENT_REQUIRED,
288 STYLE_OPT, Messages.getMessage("j2woptStyle00")),
289 new CLOptionDescriptor("use", CLOptionDescriptor.ARGUMENT_REQUIRED,
290 USE_OPT, Messages.getMessage("j2woptUse00")),
291 new CLOptionDescriptor("extraClasses",
292 CLOptionDescriptor.DUPLICATES_ALLOWED
293 + CLOptionDescriptor.ARGUMENT_REQUIRED,
294 EXTRA_CLASSES_OPT,
295 Messages.getMessage("j2woptExtraClasses00")),
296 new CLOptionDescriptor("importSchema",
297 CLOptionDescriptor.ARGUMENT_OPTIONAL,
298 IMPORT_SCHEMA_OPT,
299 Messages.getMessage("j2woptImportSchema00")),
300 new CLOptionDescriptor("classpath",
301 CLOptionDescriptor.ARGUMENT_OPTIONAL,
302 CLASSPATH_OPT,
303 Messages.getMessage("optionClasspath")),
304 new CLOptionDescriptor("implStyle",
305 CLOptionDescriptor.ARGUMENT_REQUIRED,
306 IMPL_STYLE_OPT,
307 "impelemtation Style"),
308 new CLOptionDescriptor("container",
309 CLOptionDescriptor.ARGUMENT_REQUIRED,
310 CONTAINER_OPT,
311 "the J2EE contianer")
312 };
313
314 /***
315 * Field emitter
316 */
317 protected Emitter emitter;
318
319 /***
320 * Field className
321 */
322 protected String className = null;
323
324 /***
325 * Field wsdlFilename
326 */
327 protected String wsdlFilename = null;
328
329 /***
330 * Field wsdlImplFilename
331 */
332 protected String wsdlImplFilename = null;
333
334 /***
335 * Field namespaceMap
336 */
337 protected HashMap namespaceMap = new HashMap();
338
339 /***
340 * Field mode
341 */
342 protected int mode = Emitter.MODE_ALL;
343
344 /***
345 * Field locationSet
346 */
347 boolean locationSet = false;
348
349 /***
350 * Instantiate a Java2WSDL emitter.
351 */
352 public Ws4J2eeServerCLOptionParser(String[] args, Emitter emitter) {
353 this.emitter = emitter;
354
355 CLArgsParser argsParser = new CLArgsParser(args, options);
356
357
358 if (null != argsParser.getErrorString()) {
359 System.err.println(Messages.getMessage("j2werror00", argsParser.getErrorString()));
360 printUsage();
361 return;
362 }
363
364
365 List clOptions = argsParser.getArguments();
366 int size = clOptions.size();
367
368 for (int i = 0; i < size; i++) {
369 if (parseOption((CLOption) clOptions.get(i)) == false) {
370 return;
371 }
372 }
373 module = ModuleFactory.createPackageModule(moduleLocation,new File(outPutLocation));
374
375
376 if (validateOptions() == false) {
377 return;
378 }
379
380
381 if (!namespaceMap.isEmpty()) {
382 emitter.setNamespaceMap(namespaceMap);
383 }
384 }
385
386 public Ws4J2eeServerCLOptionParser(Emitter emitter) {
387 this.emitter = emitter;
388 emitter.setLocationUrl("http://127.0.0.1");
389 }
390
391 /***
392 * addOptions
393 * Add option descriptions to the tool. Allows
394 * extended classes to add additional options.
395 *
396 * @param newOptions CLOptionDescriptor[] the options
397 */
398 protected void addOptions(CLOptionDescriptor[] newOptions) {
399 if ((newOptions != null) && (newOptions.length > 0)) {
400 CLOptionDescriptor[] allOptions =
401 new CLOptionDescriptor[options.length + newOptions.length];
402 System.arraycopy(options, 0, allOptions, 0, options.length);
403 System.arraycopy(newOptions, 0, allOptions, options.length,
404 newOptions.length);
405 options = allOptions;
406 }
407 }
408
409 /***
410 * Parse an option
411 *
412 * @param option CLOption is the option
413 * @return
414 */
415 protected boolean parseOption(CLOption option) {
416 String value;
417 boolean status = true;
418 switch (option.getId()) {
419 case CLOption.TEXT_ARGUMENT:
420 if (moduleLocation != null) {
421 System.out.println(Messages.getMessage("j2wDuplicateClass00", className,
422 option.getArgument()));
423 printUsage();
424 status = false;
425 }
426 moduleLocation = option.getArgument();
427
428 break;
429 case METHODS_ALLOWED_OPT:
430 emitter.setAllowedMethods(option.getArgument());
431 break;
432 case INHERITED_CLASS_OPT:
433 emitter.setUseInheritedMethods(true);
434 break;
435 case IMPL_CLASS_OPT:
436 emitter.setImplCls(option.getArgument());
437 break;
438 case HELP_OPT:
439 printUsage();
440 status = false;
441 break;
442 case OUTPUT_WSDL_MODE_OPT:
443 String modeArg = option.getArgument();
444 if ("All".equalsIgnoreCase(modeArg)) {
445 mode = Emitter.MODE_ALL;
446 } else if ("Interface".equalsIgnoreCase(modeArg)) {
447 mode = Emitter.MODE_INTERFACE;
448 } else if ("Implementation".equalsIgnoreCase(modeArg)) {
449 mode = Emitter.MODE_IMPLEMENTATION;
450 } else {
451 mode = Emitter.MODE_ALL;
452 System.err.println(Messages.getMessage("j2wmodeerror",
453 modeArg));
454 }
455 break;
456 case OUTPUT_OPT:
457 outPutLocation = option.getArgument();
458 wsdlFilename = option.getArgument();
459 break;
460 case INPUT_OPT:
461 emitter.setInputWSDL(option.getArgument());
462 break;
463 case OUTPUT_IMPL_OPT:
464 wsdlImplFilename = option.getArgument();
465 break;
466 case PACKAGE_OPT:
467 String packageName = option.getArgument(0);
468 String namespace = option.getArgument(1);
469 namespaceMap.put(packageName, namespace);
470 break;
471 case NAMESPACE_OPT:
472 emitter.setIntfNamespace(option.getArgument());
473 break;
474 case NAMESPACE_IMPL_OPT:
475 emitter.setImplNamespace(option.getArgument());
476 break;
477 case SERVICE_ELEMENT_NAME_OPT:
478 emitter.setServiceElementName(option.getArgument());
479 break;
480 case SERVICE_PORT_NAME_OPT:
481 emitter.setServicePortName(option.getArgument());
482 break;
483 case LOCATION_OPT:
484 emitter.setLocationUrl(option.getArgument());
485 locationSet = true;
486 break;
487 case LOCATION_IMPORT_OPT:
488 emitter.setImportUrl(option.getArgument());
489 break;
490 case METHODS_NOTALLOWED_OPT:
491 emitter.setDisallowedMethods(option.getArgument());
492 break;
493 case PORTTYPE_NAME_OPT:
494 emitter.setPortTypeName(option.getArgument());
495 break;
496 case BINDING_NAME_OPT:
497 emitter.setBindingName(option.getArgument());
498 break;
499 case STOP_CLASSES_OPT:
500 emitter.setStopClasses(option.getArgument());
501 break;
502 case TYPEMAPPING_OPT:
503 value = option.getArgument();
504 TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
505 tmr.doRegisterFromVersion(value);
506 emitter.setTypeMappingRegistry(tmr);
507 break;
508 case SOAPACTION_OPT:
509 value = option.getArgument();
510 if (value.equalsIgnoreCase("DEFAULT")) {
511 emitter.setSoapAction("DEFAULT");
512 } else if (value.equalsIgnoreCase("OPERATION")) {
513 emitter.setSoapAction("OPERATION");
514 } else if (value.equalsIgnoreCase("NONE")) {
515 emitter.setSoapAction("NONE");
516 } else {
517 System.out.println(Messages.getMessage("j2wBadSoapAction00"));
518 status = false;
519 }
520 break;
521 case STYLE_OPT:
522 value = option.getArgument();
523 if (value.equalsIgnoreCase("DOCUMENT")
524 || value.equalsIgnoreCase("RPC")
525 || value.equalsIgnoreCase("WRAPPED")) {
526 emitter.setStyle(value);
527 } else {
528 System.out.println(Messages.getMessage("j2woptBadStyle00"));
529 status = false;
530 }
531 break;
532 case USE_OPT:
533 value = option.getArgument();
534 if (value.equalsIgnoreCase("LITERAL")
535 || value.equalsIgnoreCase("ENCODED")) {
536 emitter.setUse(value);
537 } else {
538 System.out.println(Messages.getMessage("j2woptBadUse00"));
539 status = false;
540 }
541 break;
542 case EXTRA_CLASSES_OPT:
543 try {
544 emitter.setExtraClasses(option.getArgument());
545 } catch (ClassNotFoundException e) {
546 System.out.println(Messages.getMessage("j2woptBadClass00",
547 e.toString()));
548 status = false;
549 }
550 break;
551 case IMPORT_SCHEMA_OPT:
552 emitter.setInputSchema(option.getArgument());
553 break;
554 case CLASSPATH_OPT:
555 ClassUtils.setDefaultClassLoader(ClassUtils.createClassLoader(option.getArgument(),
556 this.getClass().getClassLoader()));
557 break;
558 case IMPL_STYLE_OPT:
559 this.implStyle = option.getArgument();
560 break;
561 case CONTAINER_OPT:
562 this.container = option.getArgument();
563 break;
564 default :
565 break;
566 }
567 return status;
568 }
569
570 /***
571 * validateOptions
572 * This method is invoked after the options are set to validate
573 * the option settings.
574 *
575 * @return
576 */
577 protected boolean validateOptions() {
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596 TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
597 tmr.doRegisterFromVersion("1.2");
598 emitter.setTypeMappingRegistry(tmr);
599 return true;
600 }
601
602 /***
603 * printUsage
604 * print usage information and quit.
605 */
606 protected void printUsage() {
607 String lSep = System.getProperty("line.separator");
608 StringBuffer msg = new StringBuffer();
609 msg.append("Java2WSDL "
610 + Messages.getMessage("j2wemitter00")).append(lSep);
611 msg.append(Messages.getMessage("j2wusage00",
612 "java " + getClass().getName()
613 + " [options] class-of-portType")).append(lSep);
614 msg.append(Messages.getMessage("j2woptions00")).append(lSep);
615 msg.append(CLUtil.describeOptions(options).toString());
616 msg.append(Messages.getMessage("j2wdetails00")).append(lSep);
617 System.out.println(msg.toString());
618 }
619
620 /***
621 * @return
622 */
623 public String getWsdlFilename() {
624 return wsdlFilename;
625 }
626
627 /***
628 * @param string
629 */
630 public void setWsdlFilename(String string) {
631 wsdlFilename = string;
632 }
633
634 /***
635 * @return
636 */
637 public String getClassName() {
638 return className;
639 }
640
641 /***
642 * @param string
643 */
644 public void setClassName(String string) {
645 className = string;
646 }
647
648 /***
649 * @return
650 */
651 public int getMode() {
652 return mode;
653 }
654
655 /***
656 * @return
657 */
658 public String getWsdlImplFilename() {
659 return wsdlImplFilename;
660 }
661
662 /***
663 * @param i
664 */
665 public void setMode(int i) {
666 mode = i;
667 }
668
669 /***
670 * @param string
671 */
672 public void setWsdlImplFilename(String string) {
673 wsdlImplFilename = string;
674 }
675
676 /***
677 * @return
678 */
679 public Module getModule() {
680 return module;
681 }
682
683 /***
684 * @return
685 */
686 public String getModuleLocation() {
687 return moduleLocation;
688 }
689
690 /***
691 * @param module
692 */
693 public void setModule(Module module) {
694 this.module = module;
695 }
696
697 /***
698 * @param string
699 */
700 public void setModuleLocation(String string) {
701 moduleLocation = string;
702 }
703
704 /***
705 * @return
706 */
707 public String getContanier() {
708 return container;
709 }
710
711 /***
712 * @return
713 */
714 public String getImplStyle() {
715 return implStyle;
716 }
717
718 /***
719 * @param string
720 */
721 public void setContanier(String string) {
722 container = string;
723 }
724
725 /***
726 * @param string
727 */
728 public void setImplStyle(String string) {
729 implStyle = string;
730 }
731
732 public boolean isCompile() {
733 return true;
734 }
735
736 public Map getProperties() {
737 return new HashMap();
738 }
739 }